package com.cfpl.dealer_service.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cfpl.DTO.PageQueryConditionDTO;
import com.cfpl.dealer_service.service.DealerService;
import com.cfpl.project_common.pojo.Dealer;
import com.cfpl.project_common.result.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: LYP
 * @Date: 2023/11/10 - 14:56
 * @Description: com.cfpl.dealer_service.controller
 * @version: 1.0
 */
@RestController
@Slf4j
@Api(tags = "经销商相关接口")
@RequestMapping("/dealerAdvice")
public class DealerController {

    @Autowired
    private DealerService dealerService;

    @ApiOperation("分页查询经销商")
    @PostMapping("/pageConditionQuerying")
    public BaseResult<Page<Dealer>> pageConditionQuerying(PageQueryConditionDTO pageQueryConditionDTO){
        LambdaQueryWrapper<Dealer> queryWrapper = new LambdaQueryWrapper<>();
        if (StrUtil.isNotBlank(pageQueryConditionDTO.getQueryCondition())){
            //模糊查询经销商名称 | 根据社会信用代码 查询
            queryWrapper.like(Dealer::getDealerName,pageQueryConditionDTO.getQueryCondition())
                    .or()
                    .eq(Dealer::getId,pageQueryConditionDTO.getQueryCondition());
        }
        Page<Dealer> page = dealerService.page(new Page<>(pageQueryConditionDTO.getCurrentPage(), pageQueryConditionDTO.getPageSize()),queryWrapper);

        return BaseResult.ok(page);
    }

    @ApiOperation("添加经销商信息")
    @PostMapping("/addDealerInformation")
    public BaseResult addDealerInformation(@RequestBody Dealer dealer){
        dealerService.addDealerInformation(dealer);
        return BaseResult.ok();
    }






}
